from langchain_community.vectorstores import FAISS
from langchain.embeddings.base import Embeddings
from langchain.docstore.document import Document
from typing import List
from pathlib import Path

class VectorStore:
    def __init__(self, embeddings: Embeddings):
        self.embeddings = embeddings
        
    def create_vector_store(self, documents: List[Document], persist_directory: str = None) -> FAISS:
        """创建向量存储"""
        if not documents:  # 添加检查
            raise ValueError("No documents provided for vector store creation")
            
        vector_store = FAISS.from_documents(documents, self.embeddings)
        
        if persist_directory:
            vector_store.save_local(persist_directory)
            
        return vector_store
    
    def load_vector_store(self, persist_directory: str) -> FAISS:
        """加载向量存储"""
        return FAISS.load_local(
            persist_directory, 
            self.embeddings,
            allow_dangerous_deserialization=True  # 添加此参数
        ) 